package cn.jingyuan.swan.gw.web.filter.zuul;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.core.Ordered;

/**
 * Zuul filter：sentinel
 */
@Slf4j
public class ZuulLimitSentinelFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return Ordered.HIGHEST_PRECEDENCE - 10;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        if (log.isDebugEnabled()) {
            log.debug(this.getClass().getSimpleName() + " execute before");
        }


        // logic



        if (log.isDebugEnabled()) {
            log.debug(this.getClass().getSimpleName() + " execute end");
        }

        return null;
    }

}
